package cond

import (
	"clientDemo/service/modulemgr"
)

// 表格cond---->玩家---->抽象到数据块
// 系统事件----->玩家事件-------->(模块+ID+值)数据块更新
// bind 回调  -------N对1-----> cond数据
// (模块+ID+值)数据--->cond列表---->Bind触发的列表          // 老的cond里包含触发数值的话

// bind 回调  -------N对1-----> 表达式
// (模块+ID+值)数据--->cond列表(只更新至)---->condId索引的表达式map----->一个表达式------>bind触发列表

var Name = "cond-mod"

type CondWatchEventCb func(roleId uint32, condConf *ConditionConfig, score int64)

// DataSourceFunction 获取数据源函数
type DataSourceFunction func(roleId uint32, param []interface{}) int64

// DataSourceUpdateFunction 更新数据源
type DataSourceUpdateFunction func(roleId uint32, score int64, param []interface{})

// DataComparerFunction 比较函数
type DataComparerFunction func(param1, param2 int64) bool

// DataOperateFunction 操作器
type DataOperateFunction func(condData ICondRoleItem, score int64) int64

type ICondModule interface {
	modulemgr.IModule
	// RegeditBindCond 绑定触发
	RegeditBindCond(moduleName string, cond string, cb CondWatchEventCb)

	// DispatchDataSource 通知更新
	DispatchDataSource(roleId uint32, categoryId uint32, param []interface{}, count uint64)

	// RegeditDataSource 绑定数据源
	RegeditDataSource(categoryId uint32, fn DataSourceFunction)

	// RegeditComparer 比较函数注册
	RegeditComparer(_ Comparer_Type, _ DataComparerFunction)
}

const (
	Cond_Type_Conf_1000 = 1000
	Cond_Type_Conf_1001 = 1001
	Cond_Type_Conf_1002 = 1002
	Cond_Type_Conf_1003 = 1003
	Cond_Type_Conf_1004 = 1004
	Cond_Type_Conf_1005 = 1005
	Cond_Type_Conf_1006 = 1006
	Cond_Type_Conf_1007 = 1007
	Cond_Type_Conf_1008 = 1008
	Cond_Type_Conf_1009 = 1009
)

// ConditionConfig 模拟配置数据
type ConditionConfig struct {
	Id             uint32
	Name           string
	Operate        Operate_Type    // 算子 系统计数/ 固定值
	CompareType    Comparer_Type   // 比较类型
	MatchType      Match_Type      // 0:固定匹配 1:计数匹配(条件内部单独计数)
	ValueParamType ValueParam_Type // 数据参数类型(哪个系统关联的：养成线等级)
	MatchParam     [][]string      // 触发系统(大类别，类别ID)
}

type Comparer_Type uint32

type Operate_Type uint32

type Match_Type uint32

const (
	Cond_Match_Inherent Match_Type = 0 //固定
	Cond_Match_Count    Match_Type = 1 //计数
)

type ValueParam_Type uint32

const (
	Cond_ValueParamType_Growth_Level   ValueParam_Type = 1000
	Cond_ValueParamType_Chat_Num       ValueParam_Type = 1001 //聊天次数
	Cond_ValueParamType_OpenDay        ValueParam_Type = 1002
	Cond_ValueParamType_Variable       ValueParam_Type = 1003
	Cond_ValueParamType_Mission_Status ValueParam_Type = 1004
)

// 数据源大分类
const (
	Value_Category_Growth   = 100 //养成线ID
	Value_Category_Chat     = 101
	Value_Category_Variable = 102
	Value_Category_Global   = 104
)

type ICondRoleItem interface {
	Conf() *ConditionConfig
	GetId() uint32
	GetOperateScore() int64
	SetOperateScore(op int64)
	AddTimeCount()
	GetTimeCount() int64
}
